package tasks.io.core;


import java.util.Objects;


public class Node implements Comparable<Node> {
    private String ip;
    private int port;

    public Node(String ip, int port) {
        super();
        if (ip == null) {
            ip = "0.0.0.0";
        }

        this.setIp(ip);
        this.setPort(port);
    }


    public String getIp() {
        return ip;
    }

    public int getPort() {
        return port;
    }


    public void setIp(String ip) {
        this.ip = ip;
    }

    public void setPort(int port) {
        this.port = port;
    }

    @Override
    public int hashCode() {
        return (ip + ":" + port).hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        Node other = (Node) obj;
        return ip.equals(other.getIp()) && port == other.getPort();
    }

    @Override
    public int compareTo(Node other) {
        if (other == null) {
            return -1;
        }

        if (Objects.equals(ip, other.getIp()) && Objects.equals(port, other.getPort())) {
            return 0;
        } else {
            return this.toString().compareTo(other.toString());
        }
    }


}
